#
# python-ebay - A python implementation of IContact API 2.0
# Copyright (c) 2011 Alvin Delagon (http://www.alvinatorsplayground.blogspot.com/)
# All rights reserved.
#

import urllib
import urllib2
import httplib2


class EbayResponse:

    def __init__(self, headers, raw_content, request_url):
        self.headers = headers
        self.raw_content = raw_content
        self.request_url = request_url

    def dump(self):
        s  = "HEADERS: %s\n" % self.headers
        s += "PAYLOAD: %s\n" % self.raw_content
        return s


class BaseAPI:

    def __init__(self):
        pass

    def callRemote(self, url, operation, headers={}, options={}):
        if options:
            url += "?" + urllib.urlencode(options)

        h = httplib2.Http()
        try:
            if operation == "GET":
                headers, content = h.request(url, operation,
                                             headers=headers)
            elif operation == "POST":
                pass
        except httplib2.ServerNotFoundError, e:
            raise EbayServerNotFound(e)

        return EbayResponse(headers, content, url)
